<template>
  <div>
    <div class="collection-mian">
      <div class="title">我的文件</div>
      <el-table
          :data="files"
          stripe
          style="width: 80%">
        <el-table-column
            prop="createTime"
            label="发布日期"
            width="180">
        </el-table-column>
        <el-table-column
            prop="name"
            label="名称"
            width="180">
        </el-table-column>
        <el-table-column
            fixed="right"
            label="操作"
            width="180">
          <template slot-scope="scope">
            <el-button
                size="mini"
                @click="handleCat(scope.$index, scope.row)">查看</el-button>
            <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.$index, scope.row)" v-if="ismy">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: "MyVideo",
  props: ['verifyUser'], //passvalue是父组件传递给子组件的参数
  data(){
    return{
      userId: this.verifyUser,
      files: [],
      isMy : true,
    }
  },
  methods: {
    verify(){
      let user = this.$sessionGet();
      if(user.id === this.userId){
        this.ismy = true
      }else{
        this.ismy = false
      }
    },
    handleCat(index, row){
      let a = document.createElement('a');
      a.style = 'display: none'; // 创建一个隐藏的a标签
      a.href = row.assets;
      a.target = "bank"
      document.body.appendChild(a);
      a.click(); // 触发a标签的click事件
      document.body.removeChild(a);
    },
    handleDelete(index, row) {
      let id = row.id
      this.$axios.get("resource/delById?id=" + id + "&sType=1")
          .then(resp=>{
            console.log(resp);
            this.files.splice(index, 1);
            this.files.sort();
            alert("删除成功");
          })
          .catch(error=>{
            alert("删除失败")
            console.log(error)
          })
      console.log(index);
      // rows.splice(index, 1);
    },
    getFiles(){
      this.$axios.get("resource/searchFilesByUserId?userId=" + this.userId)
          .then(resp=>{
            let res = resp.data;
            this.files = res.data;
            console.log(resp)

          })
          .catch(error=>{
            console.log(error)
          })
    }
  },
  created() {
    this.getFiles();
    this.verify()
  }
}
</script>

<style scoped>
.collection-mian {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  background-color: #fff;
  min-height: 300px;
  font-size: 30px;
}
</style>